package com.deliccio.entitys;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.deliccio.connect.Entidad;

@Entity
@Table(name = "menu")
public class Menu implements Entidad, Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idmenu", nullable = false)
    private Integer id;
    @Column(name = "codigo", length = 20)
    private String codigo;
    @Column(name = "valor", length = 20)
    private String valor;
    @Column(name = "url", length = 200)
    private String url;
    @Column(name = "codTabla", nullable = false)
    private Integer codTabla;
    @ManyToMany(mappedBy = "menuList")
    private List<Parametros> parametrosList;
    @Column(name = "todos")
    private Boolean todos;
    
    @ManyToOne
    @JoinColumn(name = "idpadre")
    public Menu idMenuPadre;

	@OneToMany(mappedBy="id", cascade = CascadeType.ALL)
    public List<Menu> subMenus;
    
    
    public Menu() {
    
    }
    
    public Menu(Integer id,String codigo,String valor,String url){
  		this.id=id;
  		this.codigo=codigo;
  		this.valor=valor;
  		this.url=url;
  	}  
    public Menu(Integer id,String codigo,String valor,String url,Menu idMenuPadre){
		this.id=id;
		this.codigo=codigo;
		this.valor=valor;
		this.url=url;
		this.idMenuPadre=idMenuPadre;
	}
    public Menu(Integer id,String codigo,String valor,String url,Boolean todos){
  		this.id=id;
  		this.codigo=codigo;
  		this.valor=valor;
  		this.url=url;
  		this.todos=todos;
  	}
	public Integer getId(){
		return id;
	}

	public void setId(Integer id){
		this.id=id;
	}

	public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getValor() {
        return valor;
    }

    public void setValor(String valor) {
        this.valor = valor;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<Parametros> getParametrosList() {
        return parametrosList;
    }

    public void setParametrosList(List<Parametros> parametrosList) {
        this.parametrosList = parametrosList;
    }

	public Boolean getTodos(){
		return todos;
	}

	public void setTodos(Boolean todos){
		this.todos=todos;
	}

	public Menu getIdMenuPadre(){
		return idMenuPadre;
	}

	public void setIdMenuPadre(Menu idMenuPadre){
		this.idMenuPadre=idMenuPadre;
	}

	public List<Menu> getSubMenus(){
		return subMenus;
	}

	public void setSubMenus(List<Menu> subMenus){
		this.subMenus=subMenus;
	}

	public Integer getCodTabla(){
		return codTabla;
	}

	public void setCodTabla(Integer codTabla){
		this.codTabla=codTabla;
	}
    
	
	  @SuppressWarnings("rawtypes")
		@Override
		public String toString() {
			String toString = "[";
			@SuppressWarnings("unused")
			String campo,iscampo = "";
			try {
				Class clase = this.getClass();
				Method[] metodos = clase.getDeclaredMethods();
				for (Method met:metodos) {					
					if (met.getName().indexOf("get") >= 0) {
						toString += met.getName()+"="+met.invoke(this, null)+" - ";
					}
				}								
				toString+="]";
			} catch (Exception e) {			
				System.out.println(e);
			}
			return toString;
		}
}
